
let __unconfig_data;
let __unconfig_stub = function (data = {}) { __unconfig_data = data };
__unconfig_stub.default = (data = {}) => { __unconfig_data = data };
import vue from '@vitejs/plugin-vue'
import {resolve} from 'path'
import {defineConfig, loadEnv} from 'vite'
import vueSetupExtend from 'vite-plugin-vue-setup-extend-plus'
import viteCompression from 'vite-plugin-compression'
import {buildConfig} from './src/utils/build'
import vueJsx from '@vitejs/plugin-vue-jsx'

const pathResolve = dir => {
	return resolve(__dirname, '.', dir)
}

const alias = {
	'/@': pathResolve('./src/'),
}

const viteConfig = defineConfig(mode => {
	const env = loadEnv(mode.mode, process.cwd())
	return {
		plugins: [vueJsx(), vue(), vueSetupExtend(), viteCompression(), JSON.parse(env.VITE_OPEN_CDN) ? buildConfig.cdn() : null],
		root: process.cwd(),
		resolve: {alias},
		base: mode.command === 'serve' ? './' : env.VITE_PUBLIC_PATH,
		optimizeDeps: {
			exclude: ['vue-demi'],
		},
		server: {
			host: '0.0.0.0',
			port: env.VITE_PORT,
			open: JSON.parse(env.VITE_OPEN),
			hmr: true,
			proxy: {
				'/api': {
					target: 'http://10.6.100.80:10002', // 目标地址 --> 服务器地址
					ws: true,
					changeOrigin: true, // 允许跨域
					rewrite: path => path.replace(/^\/api/, ''),
				},
				'/statistics': {
					target: 'http://172.26.166.11:18080', // 目标地址 --> 服务器地址
					ws: true,
					changeOrigin: true, // 允许跨域
					rewrite: path => path.replace(/^\/statistics/, ''),
				},

				'/gitea': {
					target: 'http://192.168.31.173:3000/jianghao/jianghaoTEST/issues', // 目标地址 --> 服务器地址
					ws: true,
					changeOrigin: true, // 允许跨域
					rewrite: path => path.replace(/^\/gitea/, ''),
				},

				'/Authorization': {
					target: 'http://10.6.100.80:10004', // 目标地址 --> 服务器地址
					ws: true,
					changeOrigin: true, // 允许跨域
					rewrite: path => path.replace(/^\/Authorization/, ''),
				},
				'/sta': {
					target: 'http://172.26.166.11:18080', // 目标地址 --> 服务器地址
					ws: true,
					changeOrigin: true, // 允许跨域
					rewrite: path => path.replace(/^\/sta/, ''),
				},
				'/forguncy': {
					target: 'https://10.6.100.106:8200', // 目标地址 --> 服务器地址
					ws: true,
					changeOrigin: true, // 允许跨域
					rewrite: path => path.replace(/^\/forguncy/, ''),
				},
			},
		},
		build: {
			outDir: 'dist',
			chunkSizeWarningLimit: 1500,
			rollupOptions: {
				output: {
					chunkFileNames: 'assets/js/[name]-[hash].js',
					entryFileNames: 'assets/js/[name]-[hash].js',
					assetFileNames: 'assets/[ext]/[name]-[hash].[ext]',
					manualChunks(id) {
						if (id.includes('node_modules')) {
							return id.toString().match(/\/node_modules\/(?!.pnpm)(?<moduleName>[^\/]*)\//).groups.moduleName ?? 'vender'
						}
					},
				},
				...(JSON.parse(env.VITE_OPEN_CDN) ? {external: buildConfig.external} : {}),
			},
		},
		css: {preprocessorOptions: {css: {charset: false}}},
		define: {
			__NEXT_VERSION__: JSON.stringify(process.env.npm_package_version),
			__NEXT_NAME__: JSON.stringify(process.env.npm_package_name),
		},
	}
})

const __unconfig_default =  viteConfig

if (typeof __unconfig_default === "function") __unconfig_default(...[{"command":"serve","mode":"development"}]);export default __unconfig_data;